package com.linko.intelligent.base;


import com.linko.intelligent.base.enums.ErrorEnum;

/**
 * @author yuan
 * @date 2017/6/18.
 */
public class CommonResponse<T> {

    /**
     * 请求成功
     */
    public static final int SUCCESS = 1;

    /**
     * 请求异常
     */
    public static final int FAILED = -1;

    public static final int AUTH_FAILED = -2;

    public static final int AUTH_EXPIRE = -3;

    private Integer code;

    private String msg;

    private T data;

    private String token = "";


    public CommonResponse() {
    }

    public CommonResponse(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public CommonResponse(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public CommonResponse(int code, String msg, T data, String token) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.token = token;
    }

    public CommonResponse(String msg, T data, String token) {
        this.msg = msg;
        this.data = data;
        this.token = token;
    }

    public static CommonResponse constructResponse(ErrorEnum errorEnum) {
        return new CommonResponse(errorEnum.getErrorCode(), errorEnum.getErrorMsg());
    }

    public static CommonResponse constructResponse(int code, String msg) {
        return new CommonResponse(code, msg);
    }

    public static CommonResponse constructResponse(int code, String msg, Object data) {
        return new CommonResponse(code, msg, data);
    }

    public static CommonResponse constructResponse(int code, String msg, Object data, String token) {
        return new CommonResponse(code, msg, data, token);
    }

    public static CommonResponse success(Object data) {
        return new CommonResponse(SUCCESS, "成功", data, "");
    }

    public static CommonResponse failed(Object data) {
        return new CommonResponse(FAILED, "失败", data, "");
    }

    public static CommonResponse failed(int code, String msg) {
        return new CommonResponse(code, msg, null, "");
    }

    public static CommonResponse success() {
        return new CommonResponse(SUCCESS, "成功", null, "");
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


}
